const utils = {
    install(Vue, options) {

      /**
       * 获取当前时间
       * @returns {string}
       */
      Vue.prototype.$getNow = function () {
        let now = new Date();
        let year = now.getFullYear(); // 年
        let month = now.getMonth() + 1; // 月
        let day = now.getDate(); // 日
        let hour = now.getHours(); // 时
        let minute = now.getMinutes(); // 分
        let second = now.getSeconds(); // 秒
        let formatDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
        return formatDate;
      }

      /**
       * 混合对象
       * @param objA
       * @param objB
       * @returns {*}
       */
      Vue.prototype.mergeObject = function(objA, objB) {
        Object.keys(objA).forEach(key => {
          if (objA[key] !== '' && objA[key] !== null && objA[key] !== undefined) {
            objB[key] = objA[key];
          }
        });
        return objB;
      }

      /**
       * 创建身份证号
       */
      Vue.prototype.generateIDNumber = function(areaCode){

        // 生成区域代码(前两位数字), 可以自定义或者从数据库中获取
        var regionCode = "44";

        // 随机生成出生日期(8位数字)，如19900101
        var year = Math.floor(Math.random() * (2000 - 1960 + 1)) + 1960;
        var month = Math.floor(Math.random() * 12) + 1;
        var day = Math.floor(Math.random() * 28) + 1; // 假定2月最大为28天

        if (month < 10) {
          month = "0" + month;
        }

        if (day < 10) {
          day = "0" + day;
        }

        var birthday = year + month + day;

        // 随机生成顺序码(3位数字)
        var sequenceCode = Math.floor(Math.random() * 999) + 1;

        if (sequenceCode < 100) {
          sequenceCode = "0" + sequenceCode;
        }

        if (sequenceCode < 10) {
          sequenceCode = "00" + sequenceCode;
        }

        // 计算校验码
        var idcard = regionCode + birthday + sequenceCode;
        var sum = 0;

        for (var i = 0; i < idcard.length; i++) {
          sum += parseInt(idcard.charAt(i)) * (Math.pow(2, 17 - i) % 11);
        }

        var checkCode = (12 - (sum % 11)) % 11;

        if (checkCode == 10) {
          checkCode = "X";
        }

        return idcard + checkCode;
      }

      /**
       * 创建手机号
       * @returns {string}
       */
      Vue.prototype.generatePhoneNumber = function () {
        // 生成随机的手机号前缀
        var prefixes = ['130', '131', '132', '133', '134', '135', '136', '137', '138', '139',
          '147', '150', '151', '152', '153', '155', '156', '157', '158', '159',
          '166', '170', '171', '172', '173', '175', '176', '177', '178', '180',
          '181', '182', '183', '184', '185', '186', '187', '188', '189'];
        var randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)];

        // 生成随机的手机号码主体部分（后8位）
        var mainPart = '';
        for (var i = 0; i < 8; i++) {
          mainPart += Math.floor(Math.random() * 10);
        }

        // 拼接手机号
        var phoneNumber = randomPrefix + mainPart;

        return phoneNumber;
      }



    },



}

export default utils;
